1. Field of the Invention
The invention relates generally to file systems and more particularly to an MS DOS and MS WINDOWS compatible file system for avoiding loss of data in a memory unit if power is interrupted or the memory unit is removed while new data is being written.
2. Description of the Prior Art
Standard MICROSOFT (MS) disk operating system (DOS) and WINDOWS compatible memory plug-in units, known as a CompactFlash memory cards, are commercially available for MS DOS or MS WINDOWS compatible hosts. A CompactFlash memory card uses flash-type memory devices on the card for storing data that is generated by the host. For MS DOS and MS WINDOWS compatibility the memory card is formatted according to a standard MICROSOFT format specified by American National Standards Institute (ANSI)/International Standards Association (ISO)/International Electrotechnical Commission (IEC) 9293-1994. Once the memory card has been formatted, all communication between the host and the card uses a standard protocol known as the AT attachment (ATA) protocol. The basic ATA protocol is defined by ANSI specification X3.221.1994. Newer generations of the ATA protocol are also specified by ANSI. Currently, there are specifications for ATA-2 and ATA-3. ATA commands are available for reading, writing, and erasing sectors of data. Importantly, the ATA write command erases the data in a sector of data before it writes data to that sector. CompactFlash memory cards and an ATA protocol command subset recognized by the cards are described in a xe2x80x9cCompactFlash Specification, Revision 1.4xe2x80x9d copyrighted in 1997 by the CompactFlash Association of Palo Alto, Calif.
The ATA protocol and an ATA interface form the basis for enabling hosts using an 80xc3x9786 compatible processor and MS DOS and WINDOWS file system in the host to communicate with a great variety of different memory units such as the CompactFlash memory cards, personal computer memory card international association (PCMCIA) cards, and disk memories. Hard disk memories using the ATA protocol and interface are commonly referred to as integrated drive electronics (IDE) interface drives.
All ATA commands for reading, writing, and erasing operate on one or more sectors of data at a time. Sectors are linear blocks data of a selected size, typically 512 bytes. There is no way in the ATA protocol to read, write, or erase only a single particular data byte located in the memory unit. To read a particular data byte into the host, the ATA protocol uses the ATA read command to read the entire sector in the memory unit containing the particular data byte. Writing new data is more complex. To write a particular data byte into the memory unit the ATA protocol invokes the ATA read command to read the intended sector containing the particular byte into the host; modifies the data at the particular byte within the host; and then invokes the ATA write command. The ATA write command erases the entire sector in the memory unit containing the particular data byte, and then rewrites the entire sector with the modified data. There is no ATA compatible way to rewrite modified data without first erasing the entire intended sector.
If the memory unit is removed from the host or if power is lost in the host or memory unit while the ATA write command is processing, there is a high probability that the original, existing data in the sector will be corrupted. Typically, this problem is not often encountered with desktop hosts such as personal computers having memory units that are fixed in place such as hard disks. However, the problem can and does occur for removable memories in personal computers and can be a major problem for portable hosts such as digital cameras, palmtop computers, global positioning system surveyors, and the like. Such portable hosts commonly have plug-in memory units and removable batteries. It is a common practice to use multiple plug-in memory units one at a time in a portable host and to swap the plug-in memory units between the portable host and a desktop personal computer for additional processing of stored data. Removing the memory unit or the battery while an ATA write command is processing is likely to cause existing data in the intended sector to be corrupted. If the sector contains a directory or a file allocation table (FAT), then it is possible that the data in many or all sectors in the memory unit will be irrevocably lost.
One approach, known as journaling, is used in high reliability file systems for solving this problem. The journaling approach uses redundant write operations to the memory unit. Unfortunately, this approach is not generally available for memory units that are formatted for MS DOS or MS WINDOWS systems because all the sectors in the MS DOS and MS WINDOWS format are allocated for one purpose or another. When all the sectors that are allocated for data generated by the host application are in use, the redundant write operation has no memory space in which it can temporarily store redundant data without writing over existing data. Moreover, even when there is memory space available for temporary storage, if the memory unit is removed to a new MS DOS or MS WINDOWS host during the write process, existing data can be lost to the new host because the new host will not have any way to know the particulars of the redundant write process or what it should do with the data in temporary storage. Another approach stores backup data in the host until it is known that the write process is completed. However, this approach has two disadvantages. First, the host must have a backup power source, such as an internal battery or capacitor, capable of powering the host during the write process. Such backup power source adds to the cost and physical size of the host. Second, the new host has no access to the backup data.
There is a need for a low cost MS DOS and WINDOWS compatible file system using the ATA protocol for avoiding loss of existing data in a memory unit if power is interrupted or the memory unit is removed from the host while new data is being written to the memory unit.
It is therefore an object of the present invention to provide an MS DOS and WINDOWS compatible file system using the ATA protocol for avoiding loss of existing data in a memory unit if power is interrupted or the memory unit is removed or disconnected from the host while new data is being written to the memory unit.
Briefly, in a preferred embodiment, a system includes a host of the present invention and an AT attachment (ATA) compatible memory unit. The host includes an MS DOS or WINDOWS compatible file system of the present invention including an MS DOS and WINDOWS formatter, an ATA driver, and a file manager. The formatter formats the memory unit for normal operational sectors and special reserve sectors. The ATA driver uses standard ATA protocol commands for reading, writing, and erasing data in the memory unit. The file manager modifies sectors of existing data from the memory unit with new data collected by the host to form sectors of modified data.
The file system writes modified data into the memory unit by using an ATA read command for reading the existing data into the host from an intended operational sector in the memory unit; modifying the existing data in the host with the new data; using an ATA write command for erasing a data reserve sector and writing the modified data into the data reserve sector; using an ATA write command for erasing a control reserve sector and writing control data including the location of the intended operational sector into the control reserve sector; using an ATA write command for erasing the intended operational sector and writing the modified data into the intended operational sector; and then using an ATA erase command for erasing the control reserve sector. If power is lost or the memory unit is disconnected during the ATA write to the intended operational sector, the existing data in the intended operational sector may be corrupted. However, the data reserve sector contains a copy of the modified data. At power up or when the memory unit is inserted, a warning alert is generated. The warning alert triggers the file system to use an ATA read command to check the control reserve sectors for non-erased data. When non-erased control data is found, the host uses an ATA read command for reading the copy of the modified data in the corresponding data reserve sector into the host; and uses the ATA write command for erasing and then writing the modified data into the intended operational sector at the location specified in the control data, thereby avoiding the loss of the existing data that was previously stored in the memory unit.
An advantage of the present invention is that an MS DOS WINDOWS compatible file system using the ATA protocol avoids the loss of data in a memory unit when power is lost or the memory unit is removed while writing new data to the memory unit.
Another advantage of the present invention is that the loss of existing data in a memory unit is avoided in the event that the main power goes down without the need for a backup power source for operating the host and/or the memory unit during a process of writing data to the memory unit.
These and other objects and advantages of the present invention will no doubt become obvious to those of ordinary skill in the art after having read the following detailed description of the preferred embodiments which are illustrated in the various figures.